package org.hhy.cloud.crawl.service.impl;

import org.hhy.cloud.crawl.dao.JobMonitorDao;
import org.hhy.cloud.crawl.entity.Job;
import org.hhy.cloud.crawl.entity.JobMonitor;
import org.hhy.cloud.crawl.entity.enums.JobStatusEnums;
import org.hhy.cloud.crawl.service.JobMonitorService;
import org.lht.boot.web.service.impl.BaseMybatisCrudServiceImpl;
import org.springframework.stereotype.Service;

/**
 * Description:爬虫监控
 *
 * @Author lht
 * @Date 2020/11/7 3:45 PM
 **/
@Service
public class JobMonitorServiceImpl extends BaseMybatisCrudServiceImpl<JobMonitor, String, JobMonitorDao> implements JobMonitorService {



    @Override
    public String updateJobStatus(String id, Integer status) {
        JobMonitor job = new JobMonitor();
        job.setId(id);
        job.setStatus(status);
        return patch(job);
    }

    @Override
    public String updateSuccess(String id) {
        return updateJobStatus(id, JobStatusEnums.SUCCESS.getCode());
    }

    @Override
    public String updateFail(String id) {
        return updateJobStatus(id, JobStatusEnums.ERROR.getCode());
    }

    @Override
    public String updateRunning(String id) {
        return updateJobStatus(id, JobStatusEnums.RUNNING.getCode());

    }
    @Override
    public String updateWait(String id) {
        return updateJobStatus(id, JobStatusEnums.WAIT.getCode());
    }

}
